package com.br.view;

import java.util.List;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Label;

import com.br.action.CopyFullyQualifiedClassNameAction;
import com.br.util.reflection.MetodoVisao;
import com.br.util.reflection.parser.ReflectionUtils;
import com.br.view.util.FillContentsOfTheTable;

public class MainViewOfUnitTest extends ViewPart {

	public static final String ID = "com.br.view.MainViewOfUnitTest"; //$NON-NLS-1$
	private Table table;
	private Label lblClasseName;

	public MainViewOfUnitTest() {
	}

	/**
	 * Create contents of the view part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);
		
		table = new Table(container, SWT.BORDER | SWT.FULL_SELECTION);
		table.setBounds(10, 36, 554, 158);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		
		TableColumn tblclmnNewColumn = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn.setWidth(138);
		tblclmnNewColumn.setText("Method's Name");
		
		TableColumn tblclmnNewColumn_1 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_1.setWidth(116);
		tblclmnNewColumn_1.setText("Method's Visibility");
		
		TableColumn tblclmnNewColumn_2 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_2.setWidth(148);
		tblclmnNewColumn_2.setText("Method's Parameter(s)");
		
		TableColumn tblclmnNewColumn_3 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_3.setWidth(150);
		tblclmnNewColumn_3.setText("Method's Return");
		
		Label lblClassName = new Label(container, SWT.NONE);
		lblClassName.setBounds(10, 10, 73, 14);
		lblClassName.setText("Class' Name:");
		
		lblClasseName = new Label(container, SWT.NONE);
		lblClasseName.setBounds(82, 10, 330, 14);

		createActions();
		initializeToolBar();
		initializeMenu();
		initializeTheLabel();
		initializeContentsOfTheTable();
	}

	
	public void setLblClasseName(Label lblClasseName) {
		this.lblClasseName = lblClasseName;
	}
	/**
	 * Create the actions.
	 */
	private void createActions() {
		// Create the actions
	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		IToolBarManager toolbarManager = getViewSite().getActionBars()
				.getToolBarManager();
	}

	private void initializeTheLabel(){
		
		
		lblClasseName.setText(CopyFullyQualifiedClassNameAction.nameOFTheClass.getCanonicalName());
		
		
		
	}
	
	/**
	 * Initialize the contents of the Table....
	 */
	private void initializeContentsOfTheTable(){
		
		Class classToGetTheMethods = CopyFullyQualifiedClassNameAction.nameOFTheClass;
		
		
		
		List<MetodoVisao> listOfMetodoVisao = ReflectionUtils.carregarMetodos(classToGetTheMethods);
		
		FillContentsOfTheTable.fillTable(table, listOfMetodoVisao);
		
		
	}
	
	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		IMenuManager menuManager = getViewSite().getActionBars()
				.getMenuManager();
	}

	@Override
	public void setFocus() {
		// Set the focus
	}
}
